package com.ihg.hiex.admin.dao.account;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.ihg.hiex.entity.session.Session;
import com.ihg.hiex.entity.user.Assessor;
import com.ihg.hiex.entity.user.Delegate;
import com.ihg.hiex.entity.user.KnowingRelation;

/**
 *
 * @author Ark
 *
 */
@Dao("hibernate")
public interface KnowingRelationDao {

    /**
     * @param session
     * @return
     */
    @Query("FROM KnowingRelation WHERE disabled = false AND session = :session ORDER BY assessor.id")
    public List<KnowingRelation> list(@Variable("session") Session session);
    
    /**
     * 
     * @param session
     * @param assessor
     * @param delegate
     * @return
     */
    @Query("FROM KnowingRelation WHERE disabled = false AND session = :session AND assessor = :assessor AND delegate = :delegate")
    public KnowingRelation load(@Variable("session") Session session, @Variable("assessor") Assessor assessor, @Variable("delegate") Delegate delegate);
    
    /**
     * @param session
     * @return
     */
    @Query("SELECT DISTINCT r.assessor FROM KnowingRelation r WHERE r.disabled = false AND r.session = :session ORDER BY r.assessor.id")
    public List<Assessor> listAssessor(@Variable("session") Session session);
    
    /**
     * @param session
     * @return
     */
    @Query("SELECT DISTINCT r.delegate FROM KnowingRelation r WHERE r.disabled = false AND r.session = :session ORDER BY r.delegate.id")
    public List<Delegate> listDelegate(@Variable("session") Session session);
    
    /**
     * 
     * @param session
     * @param assessor
     * @return
     */
    @Query("SELECT r.delegate FROM KnowingRelation r WHERE r.disabled = false AND r.session = :session AND r.assessor = :assessor")
    public List<Delegate> listDelegate(@Variable("session") Session session, @Variable("assessor") Assessor assessor);
    
}
